#Makefile del Progetto Lipari
CC = g++
CFLAGS = -pthread
SP1_OPTION = -L/USR/X11R6/LIB -lm -lX11
OPTIMIZE = -O2 -Wall


LIB_HEADER = libreria.h
LIB_IMPL = libreria.cpp

REG_HEADER = register.h
REG_IMPL = $(SR_DIR)/register.cpp

SP1_DIR = service_provider1
SP1_HEADER = $(SP1_DIR)/rotate_image.h $(SP1_DIR)/horizontal_flip_image.h
SP1_IMPL1 = $(SP1_DIR)/rotate_image.cpp $(SP1_DIR)/horizontal_flip_image.cpp
SP1_LIB_HEADER = response_rotate_image.h response_horizontal_flip_image.h
SP1_LIB_IMPL = response_rotate_image.cpp response_horizontal_flip_image.cpp

SP2_DIR = service_provider2
SP2_HEADER = $(SP2_DIR)/storage_image.h $(SP2_DIR)/get_image.h $(SP2_DIR)/get_list.h $(SP2_DIR)/list_image.h  
SP2_IMPL = $(SP2_DIR)/storage_image.cpp $(SP2_DIR)/get_image.cpp $(SP2_DIR)/get_list.cpp $(SP2_DIR)/list_image.cpp 
SP2_LIB_HEADER = response_storage_image.h response_get_image.h response_get_list.h
SP2_LIB_IMPL = response_storage_image.cpp response_get_image.cpp response_get_list.cpp

SR_DIR= service_register

CLI_DIR = ./client
CLI_DIR2 = ./client2
CLI_DIR3 = ./client3
CLI_DIR4 = ./client4
CLI_DIR5 = ./client5

# in questa parte vengono compilati e creati gli eseguibili di tutti i 
# nostri sorgenti

TARGETS=$(SP1_DIR)/ServiceProvider1 $(SR_DIR)/ServiceRegister $(SP2_DIR)/ServiceProvider2 $(CLI_DIR)/client_store_image $(CLI_DIR)/client_get_image $(CLI_DIR)/client_get_list $(CLI_DIR)/client_rotate_image $(CLI_DIR)/client_horizontal_flip_image $(CLI_DIR)/client $(CLI_DIR2)/client_store_image $(CLI_DIR2)/client_get_image $(CLI_DIR2)/client_get_list $(CLI_DIR2)/client_rotate_image $(CLI_DIR2)/client_horizontal_flip_image $(CLI_DIR2)/client $(CLI_DIR3)/client_store_image $(CLI_DIR3)/client_get_image $(CLI_DIR3)/client_get_list $(CLI_DIR3)/client_rotate_image $(CLI_DIR3)/client_horizontal_flip_image $(CLI_DIR3)/client $(CLI_DIR4)/client_store_image $(CLI_DIR4)/client_get_image $(CLI_DIR4)/client_get_list $(CLI_DIR4)/client_rotate_image $(CLI_DIR4)/client_horizontal_flip_image $(CLI_DIR4)/client $(CLI_DIR5)/client_store_image $(CLI_DIR5)/client_get_image $(CLI_DIR5)/client_get_list $(CLI_DIR5)/client_rotate_image $(CLI_DIR5)/client_horizontal_flip_image $(CLI_DIR5)/client


all:  clean $(TARGETS)

$(SP1_DIR)/ServiceProvider1: $(SP1_DIR)/ServiceProvider1.cpp $(LIB_HEADER) $(SP1_HEADER) $(SP1_LIB_HEADER)
	$(CC) $@.cpp $(SP1_IMPL1) $(LIB_IMPL) $(SP1_LIB_IMPL) -o $@ $(CFLAGS) $(SP1_OPTION) $(OPTIMIZE)

$(SR_DIR)/ServiceRegister : $(SR_DIR)/ServiceRegister.cpp  $(SR_DIR)/$(REG_HEADER) $(LIB_HEADER) 
	$(CC) $@.cpp $(REG_IMPL) $(LIB_IMPL) -o $@ $(CFLAGS) $(OPTIMIZE)

$(SP2_DIR)/ServiceProvider2 : $(SP2_DIR)/ServiceProvider2.cpp $(LIB_HEADER) $(SP2_HEADER) $(SP2_LIB_HEADER)
	$(CC) $@.cpp $(LIB_IMPL) $(SP2_IMPL) $(SP2_LIB_IMPL) -o $@ $(CFLAGS) $(OPTIMIZE)
 


$(CLI_DIR)/client_store_image : $(CLI_DIR)/client_store_image.cpp $(LIB_HEADER) response_storage_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_storage_image.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR)/client_get_image : $(CLI_DIR)/client_get_image.cpp $(LIB_HEADER) response_get_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_get_image.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR)/client_get_list : $(CLI_DIR)/client_get_list.cpp $(LIB_HEADER) response_get_list.h
	$(CC) $@.cpp $(LIB_IMPL) response_get_list.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR)/client_rotate_image : $(CLI_DIR)/client_rotate_image.cpp $(LIB_HEADER) response_rotate_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_rotate_image.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR)/client_horizontal_flip_image : $(CLI_DIR)/client_horizontal_flip_image.cpp $(LIB_HEADER)
	$(CC) $@.cpp $(LIB_IMPL) response_horizontal_flip_image.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR)/client : $(CLI_DIR)/client.cpp $(LIB_HEADER) $(LIB_HEADER)
	$(CC) $@.cpp  $(LIB_IMPL) -o $@ $(OPTIMIZE)



$(CLI_DIR2)/client_store_image : $(CLI_DIR2)/client_store_image.cpp $(LIB_HEADER) response_storage_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_storage_image.cpp -o $@ $(OPTIMIZE)
 
$(CLI_DIR2)/client_get_image : $(CLI_DIR2)/client_get_image.cpp $(LIB_HEADER) response_get_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_get_image.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR2)/client_get_list : $(CLI_DIR2)/client_get_list.cpp $(LIB_HEADER) response_get_list.h
	$(CC) $@.cpp $(LIB_IMPL) response_get_list.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR2)/client_rotate_image : $(CLI_DIR2)/client_rotate_image.cpp $(LIB_HEADER) response_rotate_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_rotate_image.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR2)/client_horizontal_flip_image : $(CLI_DIR2)/client_horizontal_flip_image.cpp $(LIB_HEADER) response_horizontal_flip_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_horizontal_flip_image.cpp -o $@ $(OPTIMIZE)


$(CLI_DIR2)/client : $(CLI_DIR2)/client.cpp $(LIB_HEADER)
	$(CC) $@.cpp -o $@ $(OPTIMIZE)



$(CLI_DIR3)/client_store_image : $(CLI_DIR3)/client_store_image.cpp $(LIB_HEADER) response_storage_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_storage_image.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR3)/client_get_image : $(CLI_DIR3)/client_get_image.cpp $(LIB_HEADER) response_get_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_get_image.cpp -o $@ $(OPTIMIZE)
 
$(CLI_DIR3)/client_get_list : $(CLI_DIR3)/client_get_list.cpp $(LIB_HEADER) response_get_list.h
	$(CC) $@.cpp $(LIB_IMPL) response_get_list.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR3)/client_rotate_image : $(CLI_DIR3)/client_rotate_image.cpp $(LIB_HEADER) response_rotate_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_rotate_image.cpp -o $@ $(OPTIMIZE)
 
$(CLI_DIR3)/client_horizontal_flip_image : $(CLI_DIR3)/client_horizontal_flip_image.cpp $(LIB_HEADER) response_horizontal_flip_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_horizontal_flip_image.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR3)/client : $(CLI_DIR3)/client.cpp $(LIB_HEADER)
	$(CC) $@.cpp -o $@ $(OPTIMIZE)



$(CLI_DIR4)/client_store_image : $(CLI_DIR4)/client_store_image.cpp $(LIB_HEADER) response_storage_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_storage_image.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR4)/client_get_image : $(CLI_DIR4)/client_get_image.cpp $(LIB_HEADER) response_get_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_get_image.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR4)/client_get_list : $(CLI_DIR4)/client_get_list.cpp $(LIB_HEADER) response_get_list.h
	$(CC) $@.cpp $(LIB_IMPL) response_get_list.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR4)/client_rotate_image : $(CLI_DIR4)/client_rotate_image.cpp $(LIB_HEADER) response_rotate_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_rotate_image.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR4)/client_horizontal_flip_image : $(CLI_DIR4)/client_horizontal_flip_image.cpp $(LIB_HEADER) response_horizontal_flip_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_horizontal_flip_image.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR4)/client : $(CLI_DIR4)/client.cpp $(LIB_HEADER)
	$(CC) $@.cpp -o $@ $(OPTIMIZE)


$(CLI_DIR5)/client_store_image : $(CLI_DIR5)/client_store_image.cpp $(LIB_HEADER) response_storage_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_storage_image.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR5)/client_get_image : $(CLI_DIR5)/client_get_image.cpp $(LIB_HEADER) response_get_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_get_image.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR5)/client_get_list : $(CLI_DIR5)/client_get_list.cpp $(LIB_HEADER) response_get_list.h
	$(CC) $@.cpp $(LIB_IMPL) response_get_list.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR5)/client_rotate_image : $(CLI_DIR5)/client_rotate_image.cpp $(LIB_HEADER) response_rotate_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_rotate_image.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR5)/client_horizontal_flip_image : $(CLI_DIR5)/client_horizontal_flip_image.cpp $(LIB_HEADER) response_horizontal_flip_image.h
	$(CC) $@.cpp $(LIB_IMPL) response_horizontal_flip_image.cpp -o $@ $(OPTIMIZE)

$(CLI_DIR5)/client : $(CLI_DIR5)/client.cpp $(LIB_HEADER)
	$(CC) $@.cpp -o $@ $(OPTIMIZE)


clean:
	rm -f $(TARGETS)


